It is desirable that computer programming codes be portable and reusable, i.e., that the same code for a computer algorithm can be used for different purposes and in different applications without extensive modification. Using portable and reusable codes minimizes the cost of development, maintenance, and upgrading.
A common technique for improving code portability and reusability is to encapsulate computer algorithms in modules, such as commands, routines, procedures, functions, methods, classes, and other like encapsulations known to those skilled in the art. A non-communicating module, i.e., one which does not communicate with its external environment during execution, may be completely encapsulated and thus easily ported or reused without changing its code.
However, a module may need to communicate or interact with its external environment during its execution, such as to report its status and obtain additional instructions. For example, a file-creating routine may need a confirmation from a user before overwriting an existing file. An entity that communicates information with the module is herein referred to as a “communicating partner.” A communicating partner can be an information receiver, or an information provider, or both. As can be appreciated, a communicating partner can be a human operator, a physical device, or a software component (such as an object) that interacts with the executing module. A communicating partner forms part of the external environment of the executing module. Thus, the environment changes if one of the communicating partners has been changed. For example, a command procedure receiving input from a batch file or a console input device is considered to be executing in two different environments.
The need to communicate makes it difficult to encapsulate an algorithm. A module can properly communicate with a communicating partner only if they both communicate in a compatible way. Incompatibility may arise due to the use of incompatible data formats or data types for the same information. Further, with different communicating partners, or, in different environments, different information may need to be communicated or different operations may need to be performed for processing the information. For instance, the file writing routine discussed earlier may receive instructions from a human operator through different devices (such as a keyboard or a mouse) or from a data object (such as a file) that contains pre-stored instructions. In each case, the information provider is different, the data to be transmitted is different, and the operations to be performed may be different. For example, a message of “do not overwrite” may be provided to the routine by one or more key strokes (in the case of keyboard input), by one or more mouse clicks at one or more pre-defined locations on a monitor screen (in the case of mouse input), or by a text string or a numerical value (in the case of a data object).
Under known programming approaches, code modification is often required when a communicating module is to be used in a new environment. In order to improve code portability and reusability, several programming techniques have been developed to enhance encapsulation of communicating modules. One of the known techniques is to use an intermediate object to convert the formats of communicated data when the data is transmitted between two modules with mismatching internal data formats, so that the modules can communicate with each other without the need to modify the code of either module. Another similar technique is to intercept and translate messages communicated between incompatible objects before relaying the message to the receiving object. However, code modification may still be required under either of these two approaches in cases where a module needs to communicate different information or perform different communication operations in different environments.
Thus, there is a need to enhance encapsulation of communicating algorithm modules and to improve portability and reusability of module codes encapsulating communicating algorithms.